package com.usian.order.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.usian.common.Result;
import com.usian.common.ResultCodeEnum;
import com.usian.entity.Favorites;
import com.usian.order.service.IFavoritesService;
import com.usian.vo.CollectionDetailsVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2025-01-15
 */
@RestController
@RequestMapping("/order/favorites")
public class FavoritesController {

    @Autowired
    private IFavoritesService favoritesService;

    @Operation(summary = "我的收藏详情")
    @GetMapping("/CollectionDetails/{userId}")
    public Result<CollectionDetailsVo> CollectionDetails(@PathVariable Integer userId){
        return favoritesService.CollectionDetails(userId);
    }
    @Operation(summary = "查看详情")
    @GetMapping("/findList")
    public Result<CollectionDetailsVo> findList(){
        return Result.build(favoritesService.list(), ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "添加收藏")
    @PostMapping("/addFavorites")
    public boolean addFavorites(@RequestBody Favorites favorites){
        return favoritesService.save(favorites);
    }

    @Operation(summary = "取消收藏")
    @DeleteMapping("/deleteFavorites/{userId}/{carId}")
    public boolean deleteFavorites(@PathVariable Integer userId,@PathVariable Integer carId){
        return favoritesService.remove(new LambdaQueryWrapper<>(Favorites.class).eq(Favorites::getUserId,userId).eq(Favorites::getCarId,carId));
    }

    @Operation(summary = "查看用户收藏")
    @GetMapping("/gatFavoritesAll/{userId}")
    public Result<Boolean> gatFavoritesAll(@PathVariable Integer userId){
        return Result.build(favoritesService.gatFavoritesAll(userId), ResultCodeEnum.SUCCESS);
    }
}
